/*
   @Copyright:LintCode
   @Author:   tjyemail
   @Problem:  http://www.lintcode.com/problem/merge-two-sorted-arrays
   @Language: C++
   @Datetime: 16-02-09 04:52
   */

class Solution {
public:
	/**
	 * @param A and B: sorted integer array A and B.
	 * @return: A new sorted integer array
	 */
	/** Tips: This is similar to problem 6: Merge sorted array
	 * diffience: create a new array to store the A+B
	 *
	 * */
	vector<int> mergeSortedArray(vector<int> &A, vector<int> &B) {
		// write your code here
		int m = A.size(),n = B.size(), l;
		vector<int> V(m+n);
		for(l=n+m; l && m && n;)
			V[--l] = (A[m-1]>B[n-1] ? A[--m]:B[--n]);
		for(; m; V[--l]=A[--m]);
		for(; n; V[--l]=B[--n]);
		return V;
	}
};
